home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue49 / System / OEDemoForm.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-07-26  |  2.2 KB  |  76 lines

  1. unit OEDemoForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ImgList, ComCtrls, ExtCtrls;
  8.  
  9. type
  10.   TSortOrder = ( soPriority, soAttachment, soFlag, soFrom, soSubject, soReceived );
  11.   
  12.   TForm1 = class(TForm)
  13.     ToolbarImages: TImageList;
  14.     Panel1: TPanel;
  15.     Header: THeaderControl;
  16.     ListView1: TListView;
  17.     procedure HeaderSectionClick(HeaderControl: THeaderControl; Section: THeaderSection);
  18.   private
  19.     { Private declarations }
  20.     procedure SortMessages (Order: TSortOrder; Ascending: Boolean);
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TForm1.HeaderSectionClick (HeaderControl: THeaderControl; Section: THeaderSection);
  33. var
  34.     Idx: Integer;
  35.     Sec: THeaderSection;
  36.     SortAscending: Boolean;
  37.     SortOrder: TSortOrder;
  38. begin
  39.     // Just to shut the compiler up!
  40.     SortOrder := soReceived; SortAscending := True;
  41.     with Section do begin
  42.         // Firstly, figure out which section this is.
  43.         if ImageIndex = 4 then SortOrder := soPriority else
  44.         if ImageIndex = 5 then SortOrder := soAttachment else
  45.         if ImageIndex = 33 then SortOrder := soFlag else
  46.         if Text = 'From' then SortOrder := soFrom else
  47.         if Text = 'Subject' then SortOrder := soSubject else
  48.         if Text = 'Received' then SortOrder := soReceived;
  49.  
  50.         // Next, redisplay sort marker according to selected section
  51.         if Text <> '' then begin
  52.             if ImageIndex = -1 then SortAscending := True else
  53.                 SortAscending := ImageIndex = 2;
  54.             ImageIndex := 2 + Ord (SortAscending);
  55.         end;
  56.  
  57.         // Next, remove sort marker from any other columns
  58.         for Idx := 0 to Header.Sections.Count - 1 do begin
  59.             Sec := Header.Sections [Idx];
  60.             if (Sec <> Section) and (Sec.ImageIndex in [2, 3]) then Sec.ImageIndex := -1;
  61.         end;
  62.  
  63.         // Finally, the sort !
  64.         SortMessages (SortOrder, SortAscending);
  65.     end;
  66. end;
  67.  
  68. procedure TForm1.SortMessages (Order: TSortOrder; Ascending: Boolean);
  69. begin
  70.     // An exercise for the reader....
  71. end;
  72.  
  73. end.
  74.  
  75.  
  76.